package easy;

/**
 * 反转字符串<br/>
 * 编写一个函数，其作用是将输入的字符串反转过来。输入字符串以字符数组 s 的形式给出
 *
 * @author WangChenyu
 * @since 2024-04-16 14:01
 */
public class ReverseString {

    public static void reverseString(char[] s) {
        if (s == null || s.length <= 1) {
            return;
        }

        for (int i = 0; i < s.length / 2; i++) {
            char tmp = s[i];
            s[i] = s[s.length - i - 1];
            s[s.length - i - 1] = tmp;
        }
    }

    public static void main(String[] args) {
        char[] arr = {'h', 'e', 'l', 'l', 'o'};
        reverseString(arr);
        System.out.println(arr);
    }
}
